﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Common;

namespace He.Web.manage.administrator
{
    public partial class edit_pwd : He.Web.UI.Manage
    {
        private int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            chkLoginLevel("editAdministrator");
            if (!int.TryParse(Request.QueryString["id"] as string, out this.id))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            if (!new He.BLL.administrator().Exists(this.id))
            {
                JscriptMsg(350, 230, "错误提示", "信息不存在或已被删除！", "back", "Error");
                return;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string url = CookieHelper.Get("LastListUrl");
            if (string.IsNullOrEmpty(url))
            {
                url = Request.RawUrl;
            }

            BLL.administrator bll = new BLL.administrator();
            Model.administrator model = bll.GetModel(id);

            //判断是否有修改权限
            int AdminType = Convert.ToInt32(Session["AdminType"]);
            if (AdminType > model.user_type)
            {
                JscriptPrint("您无法修改等级高于您的管理员密码！", url, "Error");
                return;
            }

            model.user_pwd = CryptoHelper.DESEncrypt(txtUserPwd.Text.Trim());
            bll.Update(model);
            SaveLogs("[管理员管理]修改管理员密码：" + model.user_name);
            JscriptPrint("修改成功啦！", url, "Success");
        }
    }
}